-
Notifications
You must be signed in to change notification settings - Fork 989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug fix for line number calculations #194
Conversation
For clarity, I believe this:
Is implemented in slither/slither/core/source_mapping/source_mapping.py Lines 15 to 33 in 82d4730
Btw. this should probably use |
@disconnect3d Yes, that was the line calculation code which caused the miscount due to CR LF being parsed as LF line endings. Thanks for the suggestion too, I've updated the code to use |
This issue aims to resolve #180 . By default, python's
open()
function parses CR LF (\r\n
) line endings as LF (\n
). During line number calculation, a byte offset is converted into line numbers by splitting the string with a\n
character, and summing up the length of each line until the correct line byte range is found. With the removal of CR control characters, a miscalculation of line lengths would cause a later-than-intended line range to be reported.This fixes the issue by adding a
newline=''
argument to theopen()
functions related to source mapping. The use of a blank new line will allow python's new line related parsing functions to work, while retaining CR LF line endings. Reference: https://stackoverflow.com/questions/20350305/python-read-crlf-text-file-as-is-with-crlfNOTE: This means that the
source_code
string property for a source mapping will now retain CR characters within them. This property is not currently used for anything but line number calculations, making it non-problematic. In the future, if code intends to print/operate on these source code properties, it should be mindful that line endings can be CR LF or LF.